<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">有我在您可放心畅饮</text>
		</view>
		<button class="btn" @tap="subscribeMessage()">乘客登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			code: null
		};
	},
	methods: {
		subscribeMessage(){
			var _this =this;
			wx.login({
			  success (res) {
			    if (res.code) {
			    const loginParam={
					type: 2,
					code: res.code
				}
				  //发起网络请求
				  _this.post("uaa/app/wechat/appLogin",loginParam,(res2)=>{
					const{data}=res2
					console.log(data)
					console.log(res2)
					  if(data.success){
						uni.setStorageSync('tokenName',data.data.tokenName)
						uni.setStorageSync('tokenValue',data.data.tokenValue)
						uni.setStorageSync('tokenContext',data.data.loginContext) 
						  uni.switchTab({
						  	url: '/pages/workbench/workbench'
						  });
						  uni.showToast({
							icon: 'success',
							title: '登录成功'
						  });
						  
					  }else{
						  uni.showToast({
							icon:'error',
							title: '请先注册！'
						  });
					  }
				  })
			    } else {
			      console.log('参数异常！' + res.errMsg)
			    }
			  }
			})
			
		},
		
		
		//this在大括号中有的时候指向就不是vue示例，为避免问题，直接把vue示例用参数接出来
		toRegisterPage(){
			const _this = this;
			uni.redirectTo({
				url:"/pages/register/register"
			})
			
		}
		
	},
	onLoad: function() {}
};
</script>

<style lang="less">
@import url('login.less');
</style>
